import React, {Component} from 'react';
import {Map} from 'immutable';
import {Relax} from 'iflux2';

import {Card, Button, message} from 'antd';
import Image from 'components/Image';
import noop from 'util/noop';
import { defaultAvatorImage } from 'constant/image.js'

@Relax
export default class User extends Component {
    static defaultProps = {
        user: Map(),
        checked: false,
        chooseUserOpt: noop
    }


    render() {
        const {user, checked} = this.props;

        return (
            <Card className="user-card" bordered={false} onClick={()=>this.chooseUser()}>
                <div className="select-box">
                    {
                        checked
                            ? <Button size="small" type="primary" shape="circle" icon="check" />
                            : <Button size="small" shape="circle">&nbsp;</Button>
                    }
                </div>
                <div>
                    <div className="avatar">
                        <Image src={user.get('jsonInfo') || defaultAvatorImage} auto={true}/>
                    </div>
                    <div className="inline-blk va-m font-14 pushl">
                        <p className="user-name" title={user.get('nickName')}><span>登录名：</span><span>{user.get('nickName')}</span></p>
                        <p className="t-grayer"><span>{user.get('userId')}</span></p>
                    </div>
                    <div className="pusht">
                        <p className="mr10 t-grayer"><span>手机：</span><span>{user.get('bindMobilePhone')}</span></p>
                        <p className="mr10 t-grayer"><span>等级：</span><span className="ov-ct" title={user.get('levelName')}>{user.get('levelName')}</span></p>
                        <p className="mr10 t-grayer"><span>状态：</span><span>{`${user.get('lockStatus') == 0 ? '已锁定' : '正常'}`}</span></p>
                    </div>
                </div>
            </Card>
        )
    }


    /**
     * 选择用户
     */
    chooseUser() {
        const {chooseUserOpt, user} = this.props;
        if (user.get('lockStatus') == 0) {
            message.warn('该用户已被锁定，需先解锁！');
            return;
        }
        chooseUserOpt(user);
    }
}